Skip to content

feat(clickhouse): support PARTITION BY after ORDER BY and ARRAY JOIN#2283

Merged
yoavcloud merged 3 commits intoapache:mainfrom
cristhiank:fix/clickhouse-partition-and-array-join
Apr 27, 2026
Merged

feat(clickhouse): support PARTITION BY after ORDER BY and ARRAY JOIN#2283
yoavcloud merged 3 commits intoapache:mainfrom
cristhiank:fix/clickhouse-partition-and-array-join

Conversation

@cristhiank
Copy link
Copy Markdown
Contributor

Summary

Two ClickHouse dialect improvements:

  1. PARTITION BY after ORDER BY — ClickHouse CREATE TABLE DDL places PARTITION BY after ORDER BY, which differs from standard SQL. The parser now accepts both orderings when using the ClickHouseDialect or GenericDialect.

  2. ARRAY JOIN support — Adds \JoinOperator\ variants for \ARRAY JOIN, \LEFT ARRAY JOIN, and \INNER ARRAY JOIN. These are ClickHouse-specific constructs for unnesting arrays inline.

Motivation

These patterns appear in production ClickHouse deployments and currently fail to parse with the ClickHouseDialect.

Changes

  • \src/parser/mod.rs: Accept PARTITION BY after ORDER BY in CREATE TABLE (ClickHouse + Generic dialect)
  • \src/ast/query.rs: New \JoinOperator\ variants: \ArrayJoin, \LeftArrayJoin, \InnerArrayJoin\ with Display impl
  • \src/ast/spans.rs: \Spanned\ impl for new \JoinOperator\ variants
  • \src/parser/mod.rs: Recognize \ARRAY JOIN, \LEFT ARRAY JOIN, \INNER ARRAY JOIN\ in \parse_joins()\
  • \ ests/sqlparser_clickhouse.rs: Added test cases for both features

@cristhiank cristhiank force-pushed the fix/clickhouse-partition-and-array-join branch from d27aeca to 097a929 Compare March 23, 2026 23:57
Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs Outdated
@cristhiank cristhiank requested a review from yoavcloud April 16, 2026 22:52
@cristhiank
Copy link
Copy Markdown
Contributor Author

Fixed a Rust/lint failure introduced by clippy 1.95 — 8 pre-existing collapsible_match patterns in parser/mod.rs, converted to match guards per clippy's suggestions. No behavior change.

@cristhiank cristhiank requested a review from yoavcloud April 17, 2026 13:02
Copy link
Copy Markdown
Contributor

@yoavcloud yoavcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @cristhiank. Please rebase and we should be good to go!

@cristhiank cristhiank force-pushed the fix/clickhouse-partition-and-array-join branch from a438712 to c6f1413 Compare April 23, 2026 19:04
@cristhiank
Copy link
Copy Markdown
Contributor Author

Thanks @yoavcloud , I just pushed the rebased branch. Appreciate it!

Cristhian Lopez Vidal and others added 3 commits April 27, 2026 06:47
ClickHouse DDL allows PARTITION BY to appear after ORDER BY, which
differs from standard SQL ordering. This change makes the parser
accept both orderings when using the ClickHouseDialect or GenericDialect.

Fixes a parse failure for production ClickHouse CREATE TABLE statements
like: CREATE TABLE t (...) ENGINE = MergeTree() ORDER BY (...) PARTITION BY expr

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ClickHouse supports ARRAY JOIN clauses for unnesting arrays inline.
This adds JoinOperator variants for ARRAY JOIN, LEFT ARRAY JOIN,
and INNER ARRAY JOIN.

These joins take a table expression (the array to unnest) rather than
a standard table reference, and do not use ON/USING constraints.

Also adds Spanned impls for the new variants in spans.rs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@cristhiank cristhiank force-pushed the fix/clickhouse-partition-and-array-join branch from c6f1413 to e7e43d0 Compare April 27, 2026 13:47
@yoavcloud yoavcloud added this pull request to the merge queue Apr 27, 2026
Merged via the queue into apache:main with commit 9833c03 Apr 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants